<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="libevent最小堆源码分析libevent最小堆算法用于处理定时器超时任务 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848">
<meta property="og:type" content="article">
<meta property="og:title" content="libevent最小堆源码分析">
<meta property="og:url" content="http://yoursite.com/2017/10/09/libevent最小堆源码分析/index.html">
<meta property="og:site_name" content="vicvon&#39;s blog">
<meta property="og:description" content="libevent最小堆源码分析libevent最小堆算法用于处理定时器超时任务 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-10-24T12:46:30.215Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="libevent最小堆源码分析">
<meta name="twitter:description" content="libevent最小堆源码分析libevent最小堆算法用于处理定时器超时任务 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/10/09/libevent最小堆源码分析/">





  <title>libevent最小堆源码分析 | vicvon's blog</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">vicvon's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-sitemap">
          <a href="/sitemap.xml" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br>
            
            站点地图
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/09/libevent最小堆源码分析/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="vicvon">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vicvon's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">libevent最小堆源码分析</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-09T17:09:59+08:00">
                2017-10-09
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/10/09/libevent最小堆源码分析/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count" data-disqus-identifier="2017/10/09/libevent最小堆源码分析/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="libevent最小堆源码分析"><a href="#libevent最小堆源码分析" class="headerlink" title="libevent最小堆源码分析"></a>libevent最小堆源码分析</h3><p>libevent最小堆算法用于处理定时器超时任务</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br></pre></td><td class="code"><pre><span class="line">/* 最小堆数据结构 */</span><br><span class="line">typedef struct min_heap</span><br><span class="line">&#123;</span><br><span class="line">    struct event** p;  /* 保存的元素，使用数组模拟堆 */</span><br><span class="line">    unsigned n, a;  /* n，当前保存的元素个数； a，数组的容量 */</span><br><span class="line">&#125; min_heap_t;</span><br><span class="line"></span><br><span class="line">/* 比较元素大小 */</span><br><span class="line">#define min_heap_elem_greater(a, b) \</span><br><span class="line">    (evutil_timercmp(&amp;(a)-&gt;ev_timeout, &amp;(b)-&gt;ev_timeout, &gt;))</span><br><span class="line"></span><br><span class="line">/* 构造最小堆 */</span><br><span class="line">void min_heap_ctor_(min_heap_t* s) &#123; s-&gt;p = 0; s-&gt;n = 0; s-&gt;a = 0; &#125;</span><br><span class="line">/* 删除最小堆 */</span><br><span class="line">void min_heap_dtor_(min_heap_t* s) &#123; if (s-&gt;p) mm_free(s-&gt;p); &#125;</span><br><span class="line">/* 最小堆某元素初始化 */</span><br><span class="line">void min_heap_elem_init_(struct event* e) &#123; e-&gt;ev_timeout_pos.min_heap_idx = -1; &#125;</span><br><span class="line">/* 最小堆是否为空 */</span><br><span class="line">int min_heap_empty_(min_heap_t* s) &#123; return 0u == s-&gt;n; &#125;</span><br><span class="line">/* 最小堆大小 */</span><br><span class="line">unsigned min_heap_size_(min_heap_t* s) &#123; return s-&gt;n; &#125;</span><br><span class="line">/* 返回堆顶元素 */</span><br><span class="line">struct event* min_heap_top_(min_heap_t* s) &#123; return s-&gt;n ? *s-&gt;p : 0; &#125;</span><br><span class="line"></span><br><span class="line">/* 往最小堆中插入数据 */</span><br><span class="line">int min_heap_push_(min_heap_t* s, struct event* e)</span><br><span class="line">&#123;</span><br><span class="line">    /* 扩容 */</span><br><span class="line">    if (min_heap_reserve_(s, s-&gt;n + 1))</span><br><span class="line">        return -1;</span><br><span class="line">    /* 元素位置调整 */</span><br><span class="line">    min_heap_shift_up_(s, s-&gt;n++, e);</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">struct event* min_heap_pop_(min_heap_t* s)</span><br><span class="line">&#123;</span><br><span class="line">    if (s-&gt;n)</span><br><span class="line">    &#123;</span><br><span class="line">        struct event* e = *s-&gt;p;</span><br><span class="line">        /* 删除堆顶元素，调整最小堆，子节点向上移或最后元素填补空缺 */</span><br><span class="line">        min_heap_shift_down_(s, 0u, s-&gt;p[--s-&gt;n]);</span><br><span class="line">        e-&gt;ev_timeout_pos.min_heap_idx = -1;</span><br><span class="line">        return e;</span><br><span class="line">    &#125;</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int min_heap_elt_is_top_(const struct event *e)</span><br><span class="line">&#123;</span><br><span class="line">    /* 判断是否为堆顶元素 */</span><br><span class="line">    return e-&gt;ev_timeout_pos.min_heap_idx == 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int min_heap_erase_(min_heap_t* s, struct event* e)</span><br><span class="line">&#123;</span><br><span class="line">    if (-1 != e-&gt;ev_timeout_pos.min_heap_idx)</span><br><span class="line">    &#123;</span><br><span class="line">        /* 元素个数减1，获取最后一个元素 */</span><br><span class="line">        struct event *last = s-&gt;p[--s-&gt;n];</span><br><span class="line">        /* 计算待删除节点的父节点 */</span><br><span class="line">        unsigned parent = (e-&gt;ev_timeout_pos.min_heap_idx - 1) / 2;</span><br><span class="line">        /* we replace e with the last element in the heap.  We might need to </span><br><span class="line">           shift it upward if it is less than its parent, or downward if it </span><br><span class="line">           is greater than one or both its children. Since the children are </span><br><span class="line">           known to be less than the parent, it can&apos;t need to shift both up </span><br><span class="line">           and down. */</span><br><span class="line">        /* 用最后一个元素替换e，如果它比它父节点小，将它提升；如果它比它的孩</span><br><span class="line">           子大，要将它降下。 */</span><br><span class="line">        if (e-&gt;ev_timeout_pos.min_heap_idx &gt; 0 &amp;&amp; min_heap_elem_greater(s-&gt;p[parent], last))</span><br><span class="line">            /* e不是根节点，并且last小于e的父节点，last替换e并提升位置 */</span><br><span class="line">            min_heap_shift_up_unconditional_(s, e-&gt;ev_timeout_pos.min_heap_idx, last);</span><br><span class="line">        else</span><br><span class="line">            min_heap_shift_down_(s, e-&gt;ev_timeout_pos.min_heap_idx, last);</span><br><span class="line">        e-&gt;ev_timeout_pos.min_heap_idx = -1;</span><br><span class="line">        return 0;</span><br><span class="line">    &#125;</span><br><span class="line">    return -1;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int min_heap_adjust_(min_heap_t *s, struct event *e)</span><br><span class="line">&#123;</span><br><span class="line">    if (-1 == e-&gt;ev_timeout_pos.min_heap_idx) </span><br><span class="line">    &#123;</span><br><span class="line">        /* e是新数据，直接插入 */</span><br><span class="line">        return min_heap_push_(s, e);</span><br><span class="line">    &#125; </span><br><span class="line">    else </span><br><span class="line">    &#123;</span><br><span class="line">        unsigned parent = (e-&gt;ev_timeout_pos.min_heap_idx - 1) / 2;</span><br><span class="line">        /* The position of e has changed; we shift it up or down</span><br><span class="line">         * as needed.  We can&apos;t need to do both. */</span><br><span class="line">        if (e-&gt;ev_timeout_pos.min_heap_idx &gt; 0 &amp;&amp; min_heap_elem_greater(s-&gt;p[parent], e))</span><br><span class="line">            min_heap_shift_up_unconditional_(s, e-&gt;ev_timeout_pos.min_heap_idx, e);</span><br><span class="line">        else</span><br><span class="line">            min_heap_shift_down_(s, e-&gt;ev_timeout_pos.min_heap_idx, e);</span><br><span class="line">        return 0;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int min_heap_reserve_(min_heap_t* s, unsigned n)</span><br><span class="line">&#123;</span><br><span class="line">    if (s-&gt;a &lt; n)</span><br><span class="line">    &#123;</span><br><span class="line">        /* 元素个数超过容量 */</span><br><span class="line">        struct event** p;</span><br><span class="line">        /* 初始大小为8，之后翻倍增加 */</span><br><span class="line">        unsigned a = s-&gt;a ? s-&gt;a * 2 : 8;</span><br><span class="line">        /* 调整之后容量还不足，直接扩大到元素个数 */</span><br><span class="line">        if (a &lt; n)</span><br><span class="line">            a = n;</span><br><span class="line">        if (!(p = (struct event**)mm_realloc(s-&gt;p, a * sizeof *p)))</span><br><span class="line">            return -1;</span><br><span class="line">        s-&gt;p = p;</span><br><span class="line">        s-&gt;a = a;</span><br><span class="line">    &#125;</span><br><span class="line">    return 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e)</span><br><span class="line">&#123;</span><br><span class="line">    unsigned parent = (hole_index - 1) / 2;</span><br><span class="line">    do</span><br><span class="line">    &#123;</span><br><span class="line">	(s-&gt;p[hole_index] = s-&gt;p[parent])-&gt;ev_timeout_pos.min_heap_idx = hole_index;</span><br><span class="line">	hole_index = parent;</span><br><span class="line">	parent = (hole_index - 1) / 2;</span><br><span class="line">    &#125; while (hole_index &amp;&amp; min_heap_elem_greater(s-&gt;p[parent], e));</span><br><span class="line">    (s-&gt;p[hole_index] = e)-&gt;ev_timeout_pos.min_heap_idx = hole_index;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e)</span><br><span class="line">&#123;</span><br><span class="line">    /* 计算出当前节点的父节点 */</span><br><span class="line">    unsigned parent = (hole_index - 1) / 2;</span><br><span class="line">    while (hole_index &amp;&amp; min_heap_elem_greater(s-&gt;p[parent], e))</span><br><span class="line">    &#123;</span><br><span class="line">        /* 父节点大于待插入元素，交换位置 */</span><br><span class="line">        (s-&gt;p[hole_index] = s-&gt;p[parent])-&gt;ev_timeout_pos.min_heap_idx = hole_index;</span><br><span class="line">        hole_index = parent;</span><br><span class="line">        /* 继续计算父节点 */</span><br><span class="line">        parent = (hole_index - 1) / 2;</span><br><span class="line">    &#125;</span><br><span class="line">    /* 将插入元素保存到适当位置 */</span><br><span class="line">    (s-&gt;p[hole_index] = e)-&gt;ev_timeout_pos.min_heap_idx = hole_index;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e)</span><br><span class="line">&#123;</span><br><span class="line">    /* 计算当前节点的子节点位置 */</span><br><span class="line">    unsigned min_child = 2 * (hole_index + 1);</span><br><span class="line">    while (min_child &lt;= s-&gt;n)</span><br><span class="line">    &#123;</span><br><span class="line">        /* 找出最小的子节点，min_child == s-&gt;n表示当前节点只有一个子节点的情况 */</span><br><span class="line">        min_child -= min_child == s-&gt;n || min_heap_elem_greater(s-&gt;p[min_child], s-&gt;p[min_child - 1]);</span><br><span class="line">        /* 子节点大于元素值直接返回 */</span><br><span class="line">        if (!(min_heap_elem_greater(e, s-&gt;p[min_child])))</span><br><span class="line">            break;</span><br><span class="line">        /* 交换位置 */</span><br><span class="line">        (s-&gt;p[hole_index] = s-&gt;p[min_child])-&gt;ev_timeout_pos.min_heap_idx = hole_index;</span><br><span class="line">        hole_index = min_child;</span><br><span class="line">        /* 继续往子节点寻找 */</span><br><span class="line">        min_child = 2 * (hole_index + 1);</span><br><span class="line">    &#125;</span><br><span class="line">    /* 将插入元素保存到适当位置 */</span><br><span class="line">    (s-&gt;p[hole_index] = e)-&gt;ev_timeout_pos.min_heap_idx = hole_index;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/10/09/C-and-the-Perils-of-Double-Checked-Locking/" rel="next" title="C++ and the Perils of Double-Checked Locking">
                <i class="fa fa-chevron-left"></i> C++ and the Perils of Double-Checked Locking
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/09/Aho-Corasick算法/" rel="prev" title="Aho-Corasick算法">
                Aho-Corasick算法 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/avatar.jpg" alt="vicvon">
            
              <p class="site-author-name" itemprop="name">vicvon</p>
              <p class="site-description motion-element" itemprop="description">记录点滴，慢慢成长</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">27</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/vicvon" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#libevent最小堆源码分析"><span class="nav-number">1.</span> <span class="nav-text">libevent最小堆源码分析</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">true</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        




  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=63333898";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  

    
      <script id="dsq-count-scr" src="https://vicvon1.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://yoursite.com/2017/10/09/libevent最小堆源码分析/';
          this.page.identifier = '2017/10/09/libevent最小堆源码分析/';
          this.page.title = 'libevent最小堆源码分析';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://vicvon1.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  





  

  

  

  
  

  

  

  

</body>
</html>
